package com.cloudfun.campusshare.repo;

import com.cloudfun.campusshare.entity.UserRelEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @author : zhangyongjie
 * @version : 1.0
 * @createTime : 2020/5/7 20:01
 * @description :
 */
public interface UserRelEntityRepo extends JpaRepository<UserRelEntity, String>, JpaSpecificationExecutor<UserRelEntity> {
    UserRelEntity findByUserId(String userId);

    List<UserRelEntity> findAllByParentId(String parentId);

    List<UserRelEntity> findAllByMerchantId(String merchantId);

    UserRelEntity findByParentIdAndUserId(String parentId,String userId);


    /**
     * 根据用户Id 查找用户以及用户建立的子用户
     * @param userId
     * @return
     */
    @Query(value = "select user_id from user_rel where user_id=?1 or parent_id = ?1",nativeQuery = true)
    List<String> findAllUserByUserId(String userId);
}
